<template>
  <!-- 分页 -->
  <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page.sync="currentPage"
    :page-sizes="pageSizes"
    :page-size.sync="pageSize"
    :layout="layout"
    :total="total"
    background
  />
</template>

<script>
export default {
  props: {
    total: {
      type: Number,
      default: 0,
    },
    //条数选择
    pageSizes: {
      type: Array,
      default: () => [10, 20, 30, 40],
    },
    //页码
    pageNo: {
      type: Number,
      default: 1,
    },
    //每页条数
    curSizes: {
      type: Number,
      default: 10,
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper",
    },
  },
  computed: {
    currentPage: {
      get() {
        return this.pageNo;
      },
      set(val) {
        this.$emit("update:pageNo", val);
      },
    },
    pageSize: {
      get() {
        return this.curSizes;
      },
      set(val) {
        this.$emit("update:curSizes", val);
      },
    },
  },
  methods: {
    //页数改变触发
    handleSizeChange() {
      this.$emit("getList");
      this.$emit("update:pageNo", 1);
    },
    //页码改变触发
    handleCurrentChange() {
      this.$emit("getList");
    },
  },
};
</script>